package com.dpad.telematicsclientapp.ui.fragment;

import android.Manifest;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Build;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.content.PermissionChecker;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.dpad.crmclientapp.android.modules.newapp.ui.fragment.THomeFragment;
import com.dpad.telematicsclientapp.android.R;
import com.dpad.telematicsclientapp.netlibrary.MainApplicaton;
import com.dpad.telematicsclientapp.netlibrary.newapp.entity.YckzZipEntity;
import com.dpad.telematicsclientapp.util.utils.T;
import com.dpad.telematicsclientapp.utils.CallBackListener;
import com.dpad.telematicsclientapp.utils.DownloadZipService;
import com.dpad.telematicsclientapp.utils.ScreenUtil;

import java.io.File;
import java.util.List;

public class DownPicUtils {


    //----------下载部分-------------
    private ServiceConnection sc;

    private PopupWindow ppw_download;//收到广播弹出下载框

    private View ppwView_download;
    private LayoutInflater inflater_download;
    private ProgressBar pro_download;
    private TextView tv_download_pro;
    private TextView tv_download_cancel;

    private static DownPicUtils downPicUtils;

    String downZipUrl="";//将下载的url设置成全局的，如果下载成功，则下次下载的时候，相同的url不用再下载

    //广播
    private LocalBroadcastManager broadcastManager;
    private IntentFilter intentFilter;
    private BroadcastReceiver mReceiver;


    private DownZibResult downZibResult;

    boolean sdCanDo = false;//sd卡是否可用或者能否读取图片路径   默认不可用   trueSD卡可用  false不可用或者图片路径识别不到

    public interface DownZibResult {
        void downLoadFail();

        void downLoadSuccess();

        void downLoadCancel();
    }

    public DownPicUtils(Activity activity, DownZibResult downZibResult) {
        this.downZibResult = downZibResult;
        //用来接收数据的广播
        broadcastManager = LocalBroadcastManager.getInstance(activity);
        intentFilter = new IntentFilter();
        intentFilter.addAction("android.intent.action.progress");
        mReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if (intent.getAction().equals("android.intent.action.progress")) {//下载中返回的

                    String pc = intent.getStringExtra("pro");
//                Log.e("ssss","进度条广播--接收--"+pc);
                    pro_download.setProgress(Integer.parseInt(pc));
                    tv_download_pro.setText(pc + "%");

                }else if (intent.getAction().equals("android.intent.action.stop")){//下载失败了
                    downZibResult.downLoadFail();
                    MainApplicaton.setDownUrl("0");//当取消了下载就设置成0,下次下载的时候，就会重新下载
                }
            }
        };
        broadcastManager.registerReceiver(mReceiver, intentFilter);
    }

    /**
     * 数据埋点专用url
     *
     * @return
     */
    public static DownPicUtils getDownPicUtils(Activity activity, DownZibResult downZibResult) {
        if (downPicUtils == null) {
            synchronized (DownPicUtils.class) {
                if (downPicUtils == null) {
                    downPicUtils = new DownPicUtils(activity, downZibResult);
                }
            }
        }
        return downPicUtils;
    }


    //下载的地址
    public void showDownload(List<YckzZipEntity.ResultBean> zipBean, Activity activity, View
            navigationUserLayout) {

        String url = zipBean.get(0).getDownloadPath();//下载的地址
        Log.e("ssss", url);
//        Log.e("ssss", "外置SD卡路径 = " + getStoragePath(this));
//        Log.e("ssss", "内置SD卡路径=" + Environment.getExternalStorageDirectory().getAbsolutePath());//  /storage/emulated/0
//        Log.e("ssss", "手机内存根目录路径=" + Environment.getDataDirectory().getParentFile().getAbsolutePath());//   /


        downloadZIP(url, activity, navigationUserLayout);


    }


    /**
     * 下载热更新需要的文件
     */
    public void downloadZIP(String url, Activity activity, View navigationUserLayout) {
        String[] permission = {
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.READ_EXTERNAL_STORAGE

        };
        if (Build.VERSION.SDK_INT >= 23) {
            if (ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE)
                    != PermissionChecker.PERMISSION_GRANTED
                    && ActivityCompat.checkSelfPermission(activity, Manifest.permission.READ_EXTERNAL_STORAGE)
                    != PermissionChecker.PERMISSION_GRANTED
            ) {
                ActivityCompat.requestPermissions(activity, permission, 101);
            } else {
                startDownload(url, activity, navigationUserLayout);
            }
        } else {
            startDownload(url, activity, navigationUserLayout);
        }

    }

    //开始下载
    public void startDownload(String url, Activity activity, View navigationUserLayout) {
        initPop(activity);
        //弹出下载框
        ppw_download.showAtLocation(navigationUserLayout, Gravity.CENTER, 0, 0);//转成dp，因为是向上移动，所以为负
        ppw_download.setFocusable(false);//设置当前的PopupWindow是否获取焦点：true-获取焦点


        sc = new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                DownloadZipService.Binder binder = (DownloadZipService.Binder) iBinder;
                binder.getService().setUpdateProgressListner(new CallBackListener() {
                    @Override

                    public void CallBack(int code, Object object) {
                        Message msgss = new Message();
                        msgss.what = 1;
                        Log.e("ssss", "Message" + msgss);
                        handlerss.sendMessage(msgss);
                    }
                });
            }

            @Override
            public void onServiceDisconnected(ComponentName componentName) {
            }
        };
        Intent intent = new Intent(activity, DownloadZipService.class);
//        intent.putExtra("zipurl", "https://github.com/xiao-er/ViewFlipper/archive/master.zip");
        intent.putExtra("zipurl", url);

        downZipUrl=url;//将下载的url设置成全局的

        if (sc != null) {
            activity.bindService(intent, sc, Context.BIND_AUTO_CREATE);
        }
    }


    Handler handlerss = new Handler(Looper.getMainLooper()) {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);



            String fourA= ScreenUtil.spiltRtoL(downZipUrl);//倒转字符串
//            String fourB=fourA.substring(4,21);//取值21位
            String fourB= fourA.substring(fourA.indexOf(".")+1,fourA.indexOf("/")); //截取.到/符号
            String fourC=ScreenUtil.spiltRtoL(fourB);//得到的应该类似于 1ppwsy_20201019142240



            if (ppw_download.isShowing()){

                T.showToastSafeOk("下载完成");

                ppw_download.dismiss();
                ppw_download.setFocusable(false);

                MainApplicaton.setDownUrl(fourC);//将url当中的名称位存起来，下次下载的时候，如果相同的url就不进行下载

                MainApplicaton.setCarTypeId(MainApplicaton.getSaleSubmodelId());//记录已经下载好的图片对应的车型
                downZibResult.downLoadSuccess();//跳转进去
            }


            Log.e("ssss", "下载完成");



        }
    };

//        if(Kits.Empty.check(MainApplicaton.getCarTypeId())){//如果是空的，代表没有下载过，此时请求下载车型图
//            //下载的接口
//            getP().chaxun("");
//        }else {//如果下载过，此时判断下载的车型图和当前车型是否一致
//            if (MainApplicaton.getCarTypeId().equals(MainApplicaton.getSaleSubmodelId())){
//                 //此时不用下载
//            }else {
//                getP().chaxun("");
//            }
//        }

    //判断文件夹是否存在的方法
    boolean isFolderExists(String path) {
        File file = new File(path);
        if (!file.exists()) {//如果不存在这个文件夹
//            if (file.mkdirs()) {//如果创建这个文件夹成功 返回true
//                return true;
//            } else {
                return false;
//            }
        }
        return true;
    }
    /**
     * 是否需要下载zip
     *
     * @return
     */
    public boolean needDownZip() {
//        if (isFolderExists(Constants.BLACKTECH_HOT_UPDATE_FILE_PATH)){//如果存在对应车型的这个文件夹
        if (isFolderExists(THomeFragment.Companion.getBLACKTECH_HOT_UPDATE_FILE_PATH())){//如果存在对应车型的这个文件夹
//            Log.e("AAAAA", "存在车型的文件夹: "+Constants.BLACKTECH_HOT_UPDATE_FILE_PATH );
            setPictureLoading();//再判断图片路径是否存在
            if (!sdCanDo){//证明有某些图片路径找不到

                return true;

            }else {
                return false;
            }
            
        }else {
//            Log.e("AAAAA", "不存在车型的文件夹: "+Constants.BLACKTECH_HOT_UPDATE_FILE_PATH );
            return true;
        }

//        if (Kits.Empty.check(MainApplicaton.getCarTypeId())) {//如果是空的，代表没有下载过，此时请求下载车型图
//            //下载的接口
//            return true;
//        } else {//如果下载过，此时判断下载的车型图和当前车型是否一致
//            if (!MainApplicaton.getCarTypeId().equals(MainApplicaton.getSaleSubmodelId())) {//不一致的时候下载
//                return true;
//            }else {//一致的时候判断图片是否存在
//                setPictureLoading();//判断图片路径是否存在
//                if (!sdCanDo){//证明有图片路径找不到，此时需要下载
//                    return true;
//                }
//            }
//        }
//        return false;
    }

    public void initPop(Activity activity) {
        //------以下为-----下载部分------------
        inflater_download = LayoutInflater.from(activity);
        //实例化ppwView
        ppwView_download = inflater_download.inflate(R.layout.progress_download, null);
        //创建ppw对象
        /**
         * 第一个参数 是ppw要展示的界面的View对象
         * 第二个参数 是ppw的宽度
         * 第三个参数 是ppw的高度
         * 第四个参数 是ppw是否可以获得焦点，true表示可以
         */
        ppw_download = new PopupWindow(ppwView_download, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);


        ppw_download.setFocusable(false);//设置当前的PopupWindow是否获取焦点：true-获取焦点
        ppw_download.setOutsideTouchable(false);//设置点击当前的popupWindow区域外的touch事件是否有效；

        ppw_download.setBackgroundDrawable(getDrawable(activity));


        pro_download = ppwView_download.findViewById(R.id.pro_download);
        tv_download_pro = ppwView_download.findViewById(R.id.tv_download_pro);
        tv_download_cancel = ppwView_download.findViewById(R.id.tv_download_cancel);


        tv_download_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ppw_download.dismiss();
                ppw_download.setFocusable(false);

                downZibResult.downLoadCancel();//取消了
//                MainApplicaton.setDownUrl("0");//当取消了下载就设置成0,下次下载的时候，就会重新下载  2020年10月22日 10:08:32 注释
                stopDownload();//点击取消下载以后，终止下载的处理方法

            }
        });


        ppw_download.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

                ppw_download.dismiss();
                ppw_download.setFocusable(false);
                activity.unbindService(sc);//一定要注销服务，否则图片下载错误的时候，再次下载会卡在0%
            }
        });


    }
    //---------以上为----下载部分------------

    //点击取消下载以后，终止下载的处理方法
    public void stopDownload(){
//        if (isFolderExists(Constants.BLACKTECH_HOT_UPDATE_FILE_PATH)){//如果存在对应车型的这个文件夹
        if (isFolderExists(THomeFragment.Companion.getBLACKTECH_HOT_UPDATE_FILE_PATH())){//如果存在对应车型的这个文件夹
//            File file = new File(Constants.BLACKTECH_HOT_UPDATE_FILE_PATH);
            File file = new File(THomeFragment.Companion.getBLACKTECH_HOT_UPDATE_FILE_PATH());
            deleteDirWihtFile(file);//删除文件夹以及文件夹下面的文件
            file.delete();
        }else {
            //不存在的话则不做处理
        }

    }
    //删除文件夹以及文件夹下面的文件
    public static void deleteDirWihtFile(File dir) {
        if (dir == null || !dir.exists() || !dir.isDirectory())
            return;
        for (File file : dir.listFiles()) {
            if (file.isFile())
                file.delete(); // 删除所有文件
            else if (file.isDirectory())
                deleteDirWihtFile(file); // 递规的方式删除文件夹
        }
        dir.delete();// 删除目录本身
    }


    //判断图片路径是否存在
    public void setPictureLoading() {
        String path_chetou = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/" + MainApplicaton.getSaleSubmodelId()+"_head_max.png";//车头
        String path_chetoulight = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/" + MainApplicaton.getSaleSubmodelId()+"_headonlight_max.png";//车头带灯
        String path_houbeixiang_close = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/" + MainApplicaton.getSaleSubmodelId()+"_trunkclose_max.png";//后备箱关
        String path_houbeixiang_open = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_trunkopen_max.png";//后备箱开
        String path_wucheding = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_topnone_max.png";//无顶车 无车门的图
        String path_youcheding = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_tophad_max.png";//有车顶   也是整车有车门的图
        String path_youhou_close = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_rightrearclose_max.png";//右后-关
        String path_youhou_open = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_rightrearopen_max.png";//右后-开
        String path_youqian_close = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_rightfrontclose_max.png";//右前-关
        String path_youqian_open = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_rightfrontopen_max.png";//右前-开
        String path_zuohou_close = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_leftrearclose_max.png";//左后-关
        String path_zuohou_open = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_leftrearopen_max.png";//左后-开
        String path_zuoqian_close = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_leftfrontclose_max.png";//左前-关
        String path_zuoqian_open = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_leftfrontopen_max.png";//左前-开

        String path_zhengche_wumen = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_bodynone_max.png";//整车无车门的图

        String path_zuoqian_close_small = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_leftfrontdoorclose_max.png";//左前-关-小门
        String path_zuohou_close_small = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_lefttreardoorclose_max.png";//左后-关-小门
        String path_youqian_close_small = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_rightfrontdoorclose_max.png";//右前-关-小门
        String path_youhou_close_small = Environment.getExternalStorageDirectory() + "/com.dpad.telematicsclientapp.android/" + MainApplicaton.getDownUrl()+"/"+ MainApplicaton.getSaleSubmodelId()+"_rightreardoorclose_max.png";//右后-关-小门


        File mfile_chetou = new File(path_chetou);
        File mfile_chetoulight = new File(path_chetoulight);
        File mfile_houbeixiang_close = new File(path_houbeixiang_close);
        File mfile_houbeixiang_open = new File(path_houbeixiang_open);
        File mfile_wucheding = new File(path_wucheding);
        File mfile_youcheding = new File(path_youcheding);
        File mfile_youhou_close = new File(path_youhou_close);
        File mfile_youhou_open = new File(path_youhou_open);
        File mfile_youqian_close = new File(path_youqian_close);
        File mfile_youqian_open = new File(path_youqian_open);
        File mfile_zuohou_close = new File(path_zuohou_close);
        File mfile_zuohou_open = new File(path_zuohou_open);
        File mfile_zuoqian_close = new File(path_zuoqian_close);
        File mfile_zuoqian_open = new File(path_zuoqian_open);

        File mfile_zhengche_wumen = new File(path_zhengche_wumen);
        File mfile_zuoqian_close_small = new File(path_zuoqian_close_small);
        File mfile_zuohou_close_small = new File(path_zuohou_close_small);
        File mfile_youqian_close_small = new File(path_youqian_close_small);
        File mfile_youhou_close_small = new File(path_youhou_close_small);


        //判断SD是否可用
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {//SD是否可用
//                String filePaths = Environment.getExternalStorageDirectory().getPath();

            sdCanDo = true;//sd卡可用

            //判断权限是否成功
            if (mfile_chetou.canRead() && mfile_chetou.exists()) { //可读且文件存在     //车头
//                    Log.v("ssss","文件是否可读："+mfile_chetou.canRead()+"文件是否存在："+mfile_chetou.exists()+"文件是否可写:"+mfile_chetou.canWrite());
                Bitmap bm_chetou = BitmapFactory.decodeFile(path_chetou);
                Drawable draw_chetou = new BitmapDrawable(bm_chetou);
//                        img_set_test.setBackgroundDrawable(draw_chetou);


            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_chetoulight.canRead() && mfile_chetoulight.exists()) { //可读且文件存在   //车头-带灯
                Bitmap bm_chetoulight = BitmapFactory.decodeFile(path_chetoulight);
                Drawable draw_chetoulight = new BitmapDrawable(bm_chetoulight);
//                        img_set_test.setBackgroundDrawable(draw_chetoulight);
            } else {
                sdCanDo = false;//图片路径识别不到
            }


            if (mfile_wucheding.canRead() && mfile_wucheding.exists()) { //可读且文件存在 //无顶车
                Bitmap bm_wucheding = BitmapFactory.decodeFile(path_wucheding);
                Drawable draw_wucheding = new BitmapDrawable(bm_wucheding);



            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_youcheding.canRead() && mfile_youcheding.exists()) { //可读且文件存在   //有车顶  也就是整张车图
                Bitmap bm_youcheding = BitmapFactory.decodeFile(path_youcheding);

            } else {
                sdCanDo = false;//图片路径识别不到
            }


            if (mfile_houbeixiang_close.canRead() && mfile_houbeixiang_close.exists()) { //可读且文件存在   //后备箱-关
                Bitmap bm_houbeixiang_close = BitmapFactory.decodeFile(path_houbeixiang_close);

            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_houbeixiang_open.canRead() && mfile_houbeixiang_open.exists()) { //可读且文件存在  //后备箱-开
                Bitmap bm_houbeixiang_open = BitmapFactory.decodeFile(path_houbeixiang_open);

            } else {
                sdCanDo = false;//图片路径识别不到
            }


            if (mfile_youhou_close.canRead() && mfile_youhou_close.exists()) { //可读且文件存在 //右后-关
                Bitmap bm_youhou_close = BitmapFactory.decodeFile(path_youhou_close);

            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_youhou_open.canRead() && mfile_youhou_open.exists()) { //可读且文件存在  //右后-开
                Bitmap bm_youhou_open = BitmapFactory.decodeFile(path_youhou_open);

            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_youqian_close.canRead() && mfile_youqian_close.exists()) { //可读且文件存在   //右前-关
                Bitmap bm_youqian_close = BitmapFactory.decodeFile(path_youqian_close);

            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_youqian_open.canRead() && mfile_youqian_open.exists()) { //可读且文件存在  //右前-开
                Bitmap bm_youqian_open = BitmapFactory.decodeFile(path_youqian_open);

            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_zuohou_close.canRead() && mfile_zuohou_close.exists()) { //可读且文件存在   //左后-关
                Bitmap bm_zuohou_close = BitmapFactory.decodeFile(path_zuohou_close);

            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_zuohou_open.canRead() && mfile_zuohou_open.exists()) { //可读且文件存在  //左后-开
                Bitmap bm_zuohou_open = BitmapFactory.decodeFile(path_zuohou_open);

            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_zuoqian_close.canRead() && mfile_zuoqian_close.exists()) { //可读且文件存在  //左前-关
                Bitmap bm_zuoqian_close = BitmapFactory.decodeFile(path_zuoqian_close);

            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_zuoqian_open.canRead() && mfile_zuoqian_open.exists()) { //可读且文件存在  //左前-开
                Bitmap bm_zuoqian_open = BitmapFactory.decodeFile(path_zuoqian_open);


            } else {
                sdCanDo = false;//图片路径识别不到
            }


            if (mfile_zhengche_wumen.canRead() && mfile_zhengche_wumen.exists()) { //可读且文件存在  //整车无车门
                Bitmap bm_zhengche_wumen = BitmapFactory.decodeFile(path_zhengche_wumen);
                Drawable draw_zhengche_wumen = new BitmapDrawable(bm_zhengche_wumen);


            } else {
                sdCanDo = false;//图片路径识别不到
            }


            if (mfile_zuoqian_close_small.canRead() && mfile_zuoqian_close_small.exists()) { //可读且文件存在 //左前-关-小门
                Bitmap bm_zuoqian_close_small = BitmapFactory.decodeFile(path_zuoqian_close_small);
                Drawable draw_zuoqian_close_small = new BitmapDrawable(bm_zuoqian_close_small);


            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_zuohou_close_small.canRead() && mfile_zuohou_close_small.exists()) { //可读且文件存在   //左后-关-小门
                Bitmap bm_zuohou_close_small = BitmapFactory.decodeFile(path_zuohou_close_small);
                Drawable draw_zuohou_close_small = new BitmapDrawable(bm_zuohou_close_small);


            } else {
                sdCanDo = false;//图片路径识别不到
            }

            if (mfile_youqian_close_small.canRead() && mfile_youqian_close_small.exists()) { //可读且文件存在  //右前-关-小门
                Bitmap bm_youqian_close_small = BitmapFactory.decodeFile(path_youqian_close_small);
                Drawable draw_youqian_close_small = new BitmapDrawable(bm_youqian_close_small);


            } else {
                sdCanDo = false;//图片路径识别不到
            }


            if (mfile_youhou_close_small.canRead() && mfile_youhou_close_small.exists()) { //可读且文件存在   //右后-关-小门
                Bitmap bm_youhou_close_small = BitmapFactory.decodeFile(path_youhou_close_small);
                Drawable draw_youhou_close_small = new BitmapDrawable(bm_youhou_close_small);


            } else {
                sdCanDo = false;//图片路径识别不到
            }

        }
    }


    private Drawable getDrawable(Activity activity) {
        ShapeDrawable bgdrawable = new ShapeDrawable(new OvalShape());
        bgdrawable.getPaint().setColor(activity.getResources().getColor(android.R.color.transparent));
        return bgdrawable;
    }

    public void hideDownDialog() {
        if (ppw_download != null && ppw_download.isShowing()) {
            ppw_download.dismiss();
        }
    }
}
